package com.logistics.utils.job;

import com.logistics.utils.configure.Configure;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@ConditionalOnProperty(name = {"configure.job.gate"}, matchIfMissing = true)
public class JobConfig {

    @Autowired
    private Configure configure;


    @Bean
    public XxlJobSpringExecutor xxlJobSpringExecutor(){
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(configure.getJob().getAddress());
        xxlJobSpringExecutor.setAppname(configure.getJob().getExecutor().getAppName());
        xxlJobSpringExecutor.setPort(configure.getJob().getExecutor().getPort());
        return xxlJobSpringExecutor;
    }
}
